package com.ruoyi.crm.controller;

import java.util.List;

import com.ruoyi.crm.domain.CrmRec;
import com.ruoyi.crm.service.ICrmRecService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 跟进记录Controller
 * 
 * @author ruoyi
 * @date 2023-03-30
 */
@RestController
@RequestMapping("/rec")
public class CrmRecController extends BaseController
{
    @Autowired
    private ICrmRecService crmRecService;

    /**
     * 查询跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:rec:list')")
    @GetMapping("/list")
    public TableDataInfo list(CrmRec crmRec)
    {
        startPage();
        List<CrmRec> list = crmRecService.selectCrmRecList(crmRec);
        return getDataTable(list);
    }

    /**
     * 导出跟进记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:rec:export')")
    @Log(title = "跟进记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(CrmRec crmRec)
    {
        List<CrmRec> list = crmRecService.selectCrmRecList(crmRec);
        ExcelUtil<CrmRec> util = new ExcelUtil<CrmRec>(CrmRec.class);
        return util.exportExcel(list, "rec");
    }

    /**
     * 获取跟进记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:rec:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(crmRecService.selectCrmRecById(id));
    }

    /**
     * 新增跟进记录
     */
    @PreAuthorize("@ss.hasPermi('system:rec:add')")
    @Log(title = "跟进记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CrmRec crmRec)
    {
        return toAjax(crmRecService.insertCrmRec(crmRec));
    }

    /**
     * 修改跟进记录
     */
    @PreAuthorize("@ss.hasPermi('system:rec:edit')")
    @Log(title = "跟进记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CrmRec crmRec)
    {
        return toAjax(crmRecService.updateCrmRec(crmRec));
    }

    /**
     * 删除跟进记录
     */
    @PreAuthorize("@ss.hasPermi('system:rec:remove')")
    @Log(title = "跟进记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(crmRecService.deleteCrmRecByIds(ids));
    }
}
